using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Impact.Web.Foundation;
using Impact.Model.Objects;
using Impact.Controllers;

namespace Impact.Web.Admin
{
    /// <summary>
    /// Page for maintaining comments on an article
    /// </summary>
    public partial class Comments : PageBase
    {

        /// <summary>
        /// overridden to handling binding on this page
        /// </summary>
        protected override void Bind()
        {
            int articleId = Int32.Parse(Request.QueryString["aid"]);

            ArticleCommentCollection comments = ArticleController.GetArticleComments(articleId);
            commentRepeater.DataSource = comments;
            commentRepeater.DataBind();
        }

        /// <summary>
        /// Event is fired when a button is clicked within the comment repeater
        /// </summary>
        protected void CommentRepeater_ItemCommand(object sender, CommandEventArgs e)
        {
            int commentId = Int32.Parse(e.CommandArgument.ToString());
            switch (e.CommandName)
            {
                case "delete":
                    ArticleController.DeleteArticleComment(commentId);
                    break;

                default:
                    throw new ArgumentException(string.Format("Command not found: {0}", e.CommandName));

            }

            Bind();

        }


    }
}
